using System.IO;
using System.Reflection;
using GrapeCity.Documents.Excel;
using System;
using System.Data;

namespace GrapeCity.Documents.Excel.Examples.Templates.TemplateSamples.ConstructionProposal
{
    class Program
    {
        static void Main(string[] args)
        {
			//create a new workbook
			var workbook = new GrapeCity.Documents.Excel.Workbook();
			
			//Load template file from resource
			var templateFile = GetResourceStream("xlsx\\Template_ConstructionProposal.xlsx");
			workbook.Open(templateFile);
			
			#region Init Data
			var datasource = new DataTable();
			datasource.Columns.Add(new DataColumn("QUANTITY", typeof(Int32)));
			datasource.Columns.Add(new DataColumn("DESCRIPTION", typeof(string)));
			datasource.Columns.Add(new DataColumn("UNIT PRICE", typeof(Double)));
			
			datasource.Rows.Add(10, "Item 1", 165);
			datasource.Rows.Add(21, "Item 2", 40);
			datasource.Rows.Add(5, "Item 3", 10.5);
			datasource.Rows.Add(164, "Item 4", 2.75);
			datasource.Rows.Add(6, "Item 5", 12);
			datasource.Rows.Add(18, "Item 6", 5.5);
			datasource.Rows.Add(1, "Item 7", 25);
			#endregion
			
			//Init template global settings
			workbook.Names.Add("TemplateOptions.KeepLineSize", "true");
			
			//Add data source
			workbook.AddDataSource("ds", datasource);
			//Invoke to process the template
			workbook.ProcessTemplate();
			        
			// Save to an excel file
			workbook.Save("ConstructionProposal.xlsx");

        }

		static Stream GetResourceStream(string resourcePath)
        {
            string resource = "ConstructionProposal.Resource." + resourcePath.Replace("\\", ".");
            var assembly = typeof(Program).GetTypeInfo().Assembly;
            return assembly.GetManifestResourceStream(resource);
        }

    }
}